<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>

    <script>
        $(function () {
            //新增和编辑
            $(".inputBtn").click(function () {
                //1.清空模态框数据
                $("#editForm input,#editForm select").val("");
                //获取绑定的json
                var json = $(this).data('json');
                console.log(json);
                // 回显
                if(json){
                    //回显id隐藏域
                    $("input[name='id']").val(json.id);
                    //名称
                    $("input[name='name']").val(json.name);
                    //所属地区
                    $("select[name='strategy.id']").val(json.strategyId);
                    //序号
                    $("input[name='sequence']").val(json.sequence);
                    //状态  布尔类型改为字符串
                    $("select[name='state']").val(json.state.toString());//json.state+""
                }else{
                    //保存
                    //回显选中的攻略id   所属地区
                    $("select[name='strategy.id']").val(${qo.strategyId!});
                }


                //回显模态框
                $("#inputModal").modal("show");
                //保存按钮
                $("#editForm").ajaxForm(function (data) {
                    reload();
                })
                $(".btn-submit").click(function () {
                    $("#editForm").submit();
                });

            });
        });
    </script>


</head>
<body>

<div class="container " style="margin-top: 20px">
   <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#assign currentMenu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <select id="selectState" class="form-control" name="strategyId">
                        <option value='-1'>全部</option>
                        <#list strategies as strategy>
                            <option value="${strategy.id}">${strategy.title}</option>
                        </#list>
                    </select>
                    <script>
                        $("select[name='strategyId']").val(${qo.strategyId!});
                    </script>
                </div>

                <button id="btn_query" class="btn btn-primary">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a class="btn btn-success inputBtn" >
                    <span class="glyphicon glyphicon-plus" ></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <thead>
                <tr>
                <thead>
                <tr>
                    <th>编号</th>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                </tr>
                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.name}</td>
                        <td>${entity.strategy.title}</td>
                        <td>${entity.sequence}</td>
                        <td>${entity.state?string("启用","禁用")}</td>
                        <td>
                            <a class="btn btn-info btn-xs btn-input inputBtn" data-json='${entity.json}' >
                                <span class="glyphicon glyphicon-pencil"></span>修改
                            </a>
                        </td>

                    </tr>
                </#list>
            </table>
           <#include "../common/page.ftl"/>
        </div>
    </div>
</div>



<#--修改模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增攻略分类</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id" >
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">所属地区：</label>
                        <div class="col-sm-6">
                            <select class="form-control"  name="strategy.id">

                                 <#list strategies as strategy>
                                     <option value="${strategy.id}">${strategy.title}</option>
                                 </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="sequence" name="sequence" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control" autocomplete="off" name="state" >
                                <option value="true">启用</option>
                                <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</body>
</html>